﻿using System.IO;
using System.Windows;
using Castle.Windsor;
using Microsoft.Win32;
using SuppKids.ViewModels;

namespace SuppKids
{
    /// <summary>
    /// Interaction logic for MenuRaskladka.xaml
    /// </summary>
    public partial class Activation : BaseWindow
    {
        public Activation(IWindsorContainer container, LicenseService licenseService)
            : base(container, licenseService)
        {
            InitializeComponent();
        }

        private void ActivateButtonClick(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                DefaultExt = ".spkl",
                Filter = "SuppKids license files (.spkl)|*.spkl"
            };

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        this.LicenseService.Activate(reader.ReadToEnd());
                    }
                }
            }
        }
    }
}
